var withdrawalsList = {
    init: function () {
        this.layuiUse();
        this.tableReload();
        $('button[name="clickBtn"]').on('click', function () {
            withdrawalsList.checkPassword();
        });
    },
    layuiUse: function () {
        layui.use(['layer', 'form', 'jquery', 'table','laydate'], function () {
            var layer = layui.layer,
                form = layui.form,
                $ = layui.$,
                table = layui.table,
                laydate = layui.laydate;

                $('.layui-body').css('width',document.body.clientWidth-200);
        
        });
    },
    tableReload: function () {
        layui.use(['layer', 'form', 'jquery', 'table','element'], function () {
            var $ = layui.$,
                element = layui.element,
                table = layui.table;
            table.render({
                elem: '#tableList',
                method: 'post',
                url: link + '/admin/withdrawal/list', //数据接口
                where: {
                    token: GetCookie('teaAdminCheckPassword')
                },
                parseData: function (res) { //res 即为原始返回的数据
                    if (res.code == 10000) {
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.message, //解析提示文本
                            "count": res.entity.total, //解析数据长度
                            "data": res.entity.list //解析数据列表
                        };
                    } else {
                        $('div[name="checkBox"]').removeClass('hide');
                        $('div[name="tableListBox"]').addClass('hide');
                    }
                },
                page: true, //开启分页
                request: {
                    pageName: 'pageNum', //页码的参数名称，默认：page
                    limitName: 'limit' //每页数据量的参数名，默认：limit
                },
                response: {
                    statusName: 'code', //规定数据状态的字段名称，默认：code
                    statusCode: 10000, //规定成功的状态码，默认：0
                    msgName: 'msg', //规定状态信息的字段名称，默认：msg
                    countName: 'count', //规定数据总数的字段名称，默认：count
                    dataName: 'data', //规定数据列表的字段名称，默认：data
                },
                cols: [
                    [ //表头
                        {
                            field: 'id',
                            title: 'ID',
                            templet: function (d) {
                                return d.id;
                            }
                        },
                        {
                            field: 'mobile',
                            title: '手机号',
                            templet: function (d) {
                                return d.mobile;
                            }
                        },
                        {
                            field: 'nickname',
                            title: '用户名',
                            templet: function (d) {
                                return d.nickname;
                            }
                        },
                        {
                            field: 'amount',
                            title: '提现金额',
                            templet: function (d) {
                                return '￥'+d.amount;
                            }
                        },
                        {
                            field: 'number',
                            title: '银行卡号',
                            templet: function (d) {
                                if(d.type==1){
                                    return '支付宝：'+d.number;
                                }else if(d.type==2){
                                    return '银行卡：'+d.number;
                                }
                            }
                        },
                        {
                            field: 'addTime',
                            title: '申请时间',
                            templet: function (d) {
                                return d.addTime;
                            }
                        },
                        {
                            field: 'status',
                            title: '状态',
                            templet: function (d) {
                                if(d.status==1){
                                    return '等待审核';
                                }else if(d.status==2){
                                    return '同意';
                                }else if(d.status==3){
                                    return '拒绝';
                                }
                            }
                        },
                        {
                            field: 'set',
                            title: '操作',
                            templet: function (d) {
                                if(d.status==1){
                                    return '<button class="layui-btn layui-btn-xs pl10 pr10 h30 line30 applyBtn" onclick="withdrawalsList.clickApply('+d.id+')">审核</button>';
                                }else{
                                    return '';
                                }
                            }
                        },
                    ]
                ],
                done: function (res, curr, count) {
                    if (res.code == 10000) {
                        $('div[name="checkBox"]').addClass('hide');
                        $('div[name="tableListBox"]').removeClass('hide');
                    } else {
                        $('div[name="checkBox"]').removeClass('hide');
                        $('div[name="tableListBox"]').addClass('hide');
                    }
                }
            });
        })

    },
    //判断是否需要输入动态口令
    checkPassword: function () {
        $.ajax({
            type: 'post',
            url: link + '/admin/checkToken',
            data: {
                'token': $('#pwd').val(),
            },
            dataType: 'json',
            success: function (res) {
                console.log(res);
                if (res.entity.flag) {
                    SetCookieDomain('teaAdminCheckPassword', res.entity.token, '');
                    $('div[name="checkBox"]').addClass('hide');
                    $('div[name="tableListBox"]').removeClass('hide');
                    location.reload();
                } else {
                    layui.use(['layer'], function () {
                        var layer = layui.layer;
                        layer.msg('动态口令输入错误！');
                    });
                }
            },
            error: function (res) {
                layui.use(['layer'], function () {
                    var layer = layui.layer;
                    layer.msg(res.message);
                });
            },
        });
    },
    clickApply:function(recordId){
        layer.open({
            title: '在线调试',
            content: '是否同意提现申请?',
            btn: ['同意', '拒绝'],
            yes: function(index, layero){
                $.ajax({
                    type: 'post',
                    url: link + '/admin/withdrawal/handle',
                    data: {
                        'token': GetCookie('teaAdminCheckPassword'),
                        'recordId':recordId,
                        'status':2,
                    },
                    dataType: 'json',
                    success: function (res) {
                        if(res.code==10000){
                            layui.use(['layer'], function () {
                                var layer = layui.layer;
                                layer.msg(res.message,{ shift: -1, time: 600 },function(){
                                    layer.closeAll();
                                    withdrawalsList.tableReload();
                                });
                            });
                        }else{
                            layui.use(['layer'], function () {
                                var layer = layui.layer;
                                layer.msg(res.message,{ shift: -1, time: 600 });
                                withdrawalsList.tableReload();
                            });
                        }
                    },
                    error: function (res) {
                        layui.use(['layer'], function () {
                            var layer = layui.layer;
                            layer.msg(res.message,{ shift: -1, time: 600 });
                            withdrawalsList.tableReload();
                        });
                    },
                });
            },
            btn2: function(index, layero){
                $.ajax({
                    type: 'post',
                    url: link + '/admin/withdrawal/handle',
                    data: {
                        'token': GetCookie('teaAdminCheckPassword'),
                        'recordId':recordId,
                        'status':3,
                    },
                    dataType: 'json',
                    success: function (res) {
                        if(res.code==10000){
                            layui.use(['layer'], function () {
                                var layer = layui.layer;
                                layer.msg(res.message,{ shift: -1, time: 600 },function(){
                                    layer.closeAll();
                                    withdrawalsList.tableReload();
                                });
                            });
                        }else{
                            layui.use(['layer'], function () {
                                var layer = layui.layer;
                                layer.msg(res.message,{ shift: -1, time: 600 });
                                withdrawalsList.tableReload();
                            });
                        }
                    },
                    error: function (res) {
                        layui.use(['layer'], function () {
                            var layer = layui.layer;
                            layer.msg(res.message,{ shift: -1, time: 600 });
                            withdrawalsList.tableReload();
                        });
                    },
                });
            }
        });  
    }
};
withdrawalsList.init();